package cn.cyan;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @Description dd
 * @Author lwq
 */
public class CompareData {
    public static void main(String[] args) {
        try {
            // 读取第一个文件内容
            BufferedReader reader1 = new BufferedReader(new FileReader("F:\\Desktop\\1.txt"));
            Set<String> content1 = new HashSet<>();
            String line;
            while ((line = reader1.readLine()) != null) {
                content1.add(line);
            }
            reader1.close();

            // 读取第二个文件内容
            BufferedReader reader2 = new BufferedReader(new FileReader("F:\\Desktop\\2.txt"));
            Set<String> content2 = new HashSet<>();
            while ((line = reader2.readLine()) != null) {
                content2.add(line);
            }
            reader2.close();

            // 找出不同的部分
            Set<String> diff = new HashSet<>(content1);
            diff.removeAll(content2);

            // 将不同部分写入新文件
            BufferedWriter writer = new BufferedWriter(new FileWriter("result.txt"));
            for (String str : diff) {
                writer.write(str);
                writer.newLine();
            }
            writer.close();

            System.out.println("操作完成！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
